<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {
    private $auth = '9def65456fc2a68a';
    public function index(){
        $myauth = trim($_REQUEST['auth']);
        if($myauth == $this->auth)
        {
            $this->grouplist();
        }
        else{
            $this->show(showMsg('我靠，非法请求，你想搞破坏么？','/index.php/Index/index',2000));
        }
        
    }

    /**
     * 获取所有报名团队列表
     */
    public function grouplist()
    {
        $groups = M('groups');
        $list = $groups->order('gid DESC')->select();
        $this->assign('group_list',$list);
        $this->display('grouplist');
    }

    /**
     * 设置为已付款
     */
    public function setpayment()
    {
        $groups = M('groups');
        $gid = empty($_REQUEST['gid'])?0:intval($_REQUEST['gid']);
        $data['ispayment']=1;
        if($gid>0){
            $flag = $groups->where('gid='.$gid)->save($data);
            if($flag){
                $this->show(showMsg('设置成功','__URL__',2000));
            }
            else if($flag == 0){
                $this->show(showMsg('您已经设置为已付款，无需重复操作','__URL__/grouplist/auth/'.$this->auth.'',3000));
            }
            else{
                $this->show(showMsg('设置失败','__URL__/grouplist/auth/'.$this->auth.'',2000));
            }
        }
        else{
            $this->show(showMsg('参数无效','__URL__/grouplist/auth/'.$this->auth.'',2000));
        }
        
    }

    /**
     * 删除报名团队
     */
    public function delgroup()
    {
        $groups = M('groups');
        $gid = empty($_REQUEST['gid'])?0:intval($_REQUEST['gid']);
        if($gid>0){
            $avatar = $groups->where('gid='.$gid)->getField('avatar');

            $flag = $groups->where('gid='.$gid)->delete();
            if($flag){
                @unlink($avatar);
                $players = M('players');
                $players->where('gid='.$gid)->delete();
                $this->show(showMsg('删除成功','__URL__/grouplist/auth/'.$this->auth.'',2000));
            }
            else{
                $this->show(showMsg('删除成功','__URL__/grouplist/auth/'.$this->auth.'',2000));
            }
        }
        else{
            $this->show(showMsg('参数无效','__URL__/grouplist/auth/'.$this->auth.'',2000));
        }
    }

    /**
     * 获取玩家列表信息
     */
    public function playerlist()
    {
        $gid = empty($_REQUEST['gid'])?0:intval($_REQUEST['gid']);
        $group_name = $_REQUEST['group_name'];
        $players = M('players');
        $groups = M('groups');
        $glist = $groups->where('gid='.$gid)->select();
        $list = $players->where('gid='.$gid)->select();
        $str = '<table class="dataTable" cellpadding="0" cellspacing="0" border="1">';
        $str .= '<tr><th colspan="5"><h3>【'.$glist[0]['group_name'].'】战队详细信息</h3></th></tr>';
        foreach($glist as $k => $v)
        {
            $str .= '<tr>';
            $str .= '   <th>战队名称：</th>';
            $str .= '   <td>'.$v['group_name'].'</td>';
            $str .= '   <th>领队姓名：</th>';
            $str .= '   <td>'.$v['leader_name'].'</td>';
            $str .= '   <td rowspan="2">是否缴费：';
            if($v['ispayment']==1){
                $str .= '<font color="#339933">已付款</font>';
            }
            else{
                $str .= '<font color="#CC3333">未付款</font>';
            }
            $str .= '</td>';
            $str .= '</tr>';
            $str .= '<tr>';
            $str .= '   <th>联系QQ：</th>';
            $str .= '   <td>'.$v['qq'].'</td>';
            $str .= '   <th>联系手机：</th>';
            $str .= '   <td>'.$v['mobile'].'</td>';
            $str .= '</tr>';
        }
        $str .= '<tr>';
        $str .= '    <th>玩家序号</th>';
        $str .= '    <th>玩家姓名</th>';
        $str .= '    <th>玩家性别</th>';
        $str .= '    <th>玩家年龄</th>';
        $str .= '    <th>身份证号</th>';
        $str .= '</tr>';
        foreach($list as $k => $v)
        {
            $str .= '<tr>';
            $str .= '   <td>'.$v['pid'].'</td>';
            $str .= '   <td>'.$v['player_name'].'</td>';
            $str .= '   <td>'.$v['player_sex'].'</td>';
            $str .= '   <td>'.$v['player_age'].'</td>';
            $str .= '   <td>'.$v['player_idcard'].'</td>';
            $str .= '</tr>';
        }
        $str .= '</table>';
        echo $str;
    }
}